package cn.ellacat.game.guess;

import lombok.extern.slf4j.Slf4j;

import static cn.ellacat.game.guess.Constants.DEFAULT_ERROR_INT;
import static cn.ellacat.game.guess.Constants.DEFAULT_ERROR_STR;

/**
 * @author wjc133
 */
@Slf4j
public class IoWrapper {
    private final IoController controller = Game.getInstance().getIoController();
    private static final IoWrapper INSTANCE = new IoWrapper();

    private IoWrapper() {
        // no-op
    }

    public static IoWrapper getInstance() {
        return INSTANCE;
    }

    public int inInt() {
        try {
            return this.controller.inInt();
        } catch (final GuessYouException e) {
            log.error("inInt error", e);
        }
        return DEFAULT_ERROR_INT;
    }

    public String inString() {
        try {
            return this.controller.inString();
        } catch (final GuessYouException e) {
            log.error("inString error", e);
        }
        return DEFAULT_ERROR_STR;
    }

    public Object inObject() {
        try {
            return this.controller.inObject();
        } catch (final GuessYouException e) {
            log.error("inObject error", e);
        }
        return null;
    }

    public <T> T inObject(final Class<T> clz) {
        try {
            return this.controller.inObject(clz);
        } catch (final GuessYouException e) {
            log.error("inObject error", e);
        }
        return null;
    }

    public void outLine(final String str) {
        try {
            this.controller.outLine(str);
        } catch (final GuessYouException e) {
            log.error("outLine error", e);
        }
    }

    public void outLine() {
        try {
            this.controller.outLine("");
        } catch (final GuessYouException e) {
            log.error("outLine error", e);
        }
    }

    public void outString(final String str) {
        try {
            this.controller.outString(str);
        } catch (final GuessYouException e) {
            log.error("outString error", e);
        }
    }

    public void outInt(final int i) {
        try {
            this.controller.outInt(i);
        } catch (final GuessYouException e) {
            log.error("outInt error", e);
        }
    }

    public void outObject(final Object obj) {
        try {
            this.controller.outObject(obj);
        } catch (final GuessYouException e) {
            log.error("outObject error", e);
        }
    }
}
